//
//  BuyVcCell.m
//  Wy_BuyBooks
//
//  Created by wangyang on 2020/2/6.
//  Copyright © 2020 wangyang. All rights reserved.
//

#import "BuyVcCell.h"

@implementation BuyVcCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

        [self BackView];
        
        NSArray *fuleiArray = @[@"傅雷家书",@"傅雷",@"综合评分：4.8",@"¥29.50"];
               for (int i = 0; i<fuleiArray.count; i++) {
                   UILabel *labe = [UILabel labelWithContent:fuleiArray[i]superView:self.BackView textColor:WyBlackColor font:WySYSTEMFONT(14) textAlignment:NSTextAlignmentLeft];
                   [labe mas_makeConstraints:^(MASConstraintMaker *make) {
                       make.size.equalTo(CGSizeMake(BiLiWidth(200), BiLiWidth(20)));
                       make.left.equalTo(self.PicImg.right).offset(BiLiWidth(10));
                       make.top.equalTo(self.LineView.bottom).offset(BiLiWidth(10)+BiLiWidth(25)*i);
                   }];
                   labe.tag = i;
                   if (labe.tag == 0) {
                       _NameLabe = labe;
                   }else if (labe.tag == 1)
                   {
                       _UserNameLabe = labe;
                       _UserNameLabe.textColor = UIColorFromRGB(0x999999);
                       
                   }
                   else if (labe.tag == 2)
                   {
                       _ScoreLabe = labe;
                       _ScoreLabe.textColor = UIColorFromRGB(0xFADB14);
               
                   }
                   else if (labe.tag == 3)
                   {
                       _MoneyLabe = labe;
                       _MoneyLabe.textColor = UIColorFromRGB(0xFF4949);
                       
                   }
               }
        
        
        NSArray *arry = @[@"联系商家",@"取消订单"];
        for (int i = 0; i<arry.count; i++) {
            UIButton *btn = [UIButton ButtonWithText:arry[i] superView:self.BackView TextNormalcolor:WyWhiteColor backgroundColor:[UIColor clearColor] fontSize:14 addTarget:self selector:@selector(selector:)];
            WyViewRadius(btn, BiLiWidth(15));
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.size.equalTo(CGSizeMake(BiLiWidth(70), BiLiWidth(30)));
                make.bottom.mas_offset(BiLiWidth(-10));
                make.right.mas_offset(BiLiWidth(-100)+BiLiWidth(80)*i);
            }];
            btn.tag = i;
            if (btn.tag == 0) {
                [btn setBackgroundColor:UIColorFromRGB(0xFF3737)];
            }
            else
            {
                [btn setBackgroundColor:UIColorFromRGB(0xFADB14)];
                
            }
        }
        
    }
    return self;
}
- (void)setIndexPath:(NSIndexPath *)IndexPath{
    
    _IndexPath = IndexPath;
    
}
- (UIView *)BackView

{
    if (!_BackView) {
        
        _BackView = [[UIView alloc]init];
        [self addSubview:_BackView];
        _BackView.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
        _BackView.layer.shadowColor = [UIColor colorWithRed:8/255.0 green:6/255.0 blue:6/255.0 alpha:0.1].CGColor;
        _BackView.layer.shadowOffset = CGSizeMake(0,2);
        _BackView.layer.shadowOpacity = 1;
        _BackView.layer.shadowRadius = 6;
        _BackView.layer.cornerRadius = 10;
        [_BackView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(WySCREENWIDTH-BiLiWidth(30), BiLiWidth(205)));
            make.top.mas_offset(BiLiWidth(10));
            make.centerX.mas_offset(0);
        }];
        [self OrderLabe];
        [self LineView];
        [self PicImg];
        [self TwoLineView];
    }
    return _BackView;
}
- (UILabel *)OrderLabe

{
    if (!_OrderLabe) {
        
        _OrderLabe = [UILabel labelWithContent:@"订单编号：672326717" superView:self.BackView textColor:WyBlackColor font:WySYSTEMFONT(14) textAlignment:NSTextAlignmentLeft];
        [_OrderLabe mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(BiLiWidth(200), BiLiWidth(20)));
            make.left.mas_offset(BiLiWidth(20));
            make.top.mas_offset(BiLiWidth(14));
        }];
    }
    return _OrderLabe;
}

- (UIView *)LineView

{
    if (!_LineView) {
        
        _LineView = [[UIView alloc]init];
        [self.BackView addSubview:_LineView];
        _LineView.backgroundColor = UIColorFromRGB(0xFAFAFA);
        [_LineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(WySCREENWIDTH-BiLiWidth(50), BiLiWidth(1)));
            make.centerX.mas_offset(BiLiWidth(0));
            make.top.equalTo(self.OrderLabe.bottom).offset(BiLiWidth(9));
        }];
        
    }
    return _LineView;
}
- (UIImageView *)PicImg

{
    if (!_PicImg) {
        _PicImg = [UIImageView imageWithImgName:@"" superView:self.BackView];
        _PicImg.backgroundColor = WyColor;
        WyViewRadius(_PicImg, BiLiWidth(5));
        [_PicImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(BiLiWidth(65), BiLiWidth(95)));
            make.top.equalTo(self.LineView.bottom).offset(BiLiWidth(10));
            make.left.mas_offset(BiLiWidth(20));
        }];
    }
    return _PicImg;
}

- (UIView *)TwoLineView

{
    if (!_TwoLineView) {
        
        _TwoLineView = [[UIView alloc]init];
        [self.BackView addSubview:_TwoLineView];
        _TwoLineView.backgroundColor = UIColorFromRGB(0xFAFAFA);
        [_TwoLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(WySCREENWIDTH-BiLiWidth(50), BiLiWidth(1)));
            make.centerX.mas_offset(BiLiWidth(0));
            make.top.equalTo(self.PicImg.bottom).offset(BiLiWidth(10));
        }];
        
    }
    return _LineView;
}


-(void)selector:(UIButton *)button
{
    
    if (button.tag == 0) {
        
        if ([_delegate respondsToSelector:@selector(ContactMerchantClickIndexPath:)]) {
            [_delegate ContactMerchantClickIndexPath:_IndexPath];
            NSLog(@"联系商家");
        }
    }
    else
    {
        if ([_delegate respondsToSelector:@selector(CancelOrderClickIndexPath:)]) {
            [_delegate CancelOrderClickIndexPath:_IndexPath];
            NSLog(@"取消订单");
        }
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
